package com.xhwl.data.service.impl.devplatform;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhwl.common.pojo.cent.sdata.devplatform.Module;
import com.xhwl.common.query.cent.sdata.devplatform.ModuleQuery;
import com.xhwl.data.dao.devplatform.IModuleDao;
import com.xhwl.data.service.devplatform.IModuleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 模块表 服务实现类
 * </p>
 *
 * @author yf
 * @since 2022-11-24
 */
@Service
public class ModuleServiceImpl extends ServiceImpl<IModuleDao, Module> implements IModuleService {

    @Autowired
    private IModuleDao moduleDao;

    @Override
    public Page<Module> page(ModuleQuery query) {
        String str = query.getLikeNameOrCode();
        boolean flag = StringUtils.isNotBlank(str);
        return moduleDao.selectPage(new Page<>(query.getCurrent(), query.getSize()),
                new QueryWrapper<Module>().like(flag, "name", str)
                        .or(flag)
                        .like(flag, "code", str));
    }

    @Override
    public List<Module> list(ModuleQuery query) {
        QueryWrapper<Module> queryWrapper = new QueryWrapper<>();
        if (null != query.getLikeNameOrCode() && query.getLikeNameOrCode().trim().length() != 0) {
            queryWrapper.like("name", query.getLikeNameOrCode()).or().like("code", query.getLikeNameOrCode());
        }
        if (!CollectionUtils.isEmpty(query.getIdList())) {
            queryWrapper.in("id", query.getIdList());
        }
        List<Module> modules = moduleDao.selectList(queryWrapper);
        return modules;
    }

    @Override
    public Module getOne(Integer moduleId) {
        return moduleDao.selectById(moduleId);
    }

}
